Component({
  properties: {
    date: {
      type: Number,
      observer: function (newData, oldData) {
        this.setEndTime(newData)
      }
    }
  },
  data: {
    // 时间倒计时
    minutes: 0,
    seconds: 0,
    hours:0,
    days:0,
    pollingTime: null,
    timeAll: 0
  },
  methods: {
    // 设置倒计时
    setEndTime: function (time) {
      this.setData({
        timeAll: time,
        minutes: new Date(time).getMinutes(),
        seconds: new Date(time).getSeconds()
      })
      this.setData({
        pollingTime: setInterval(() => {
          var myDate = new Date(this.data.timeAll - 1000);
          this.setData({
            timeAll: myDate
          })
          var days = parseInt(myDate.getTime() / (60 * 60 * 1000 * 24));
          var hours = parseInt(myDate.getTime() / 60 / 60 / 1000 % 24);
          var sec = myDate.getSeconds();
          var minus = myDate.getMinutes();
          var sec = myDate.getSeconds();
          if (sec <= 0 && minus <= 0) {
            this.setData({
              days:0,
              hours:0,
              minutes: 0,
              seconds: 0
            })
            clearInterval(this.data.pollingTime)
            // 倒计时为0发射结束事件
            this.triggerEvent('orderLoad')
            return
          }
          this.setData({
            days: days,
            hours: hours,
            minutes: minus,
            seconds: sec
          })
        }, 1000)
      })
    },
  }
})